/*
 * @Author: c
 * @Date: 2024-01-12 13:42:03
 * @LastEditTime: 2024-03-17 02:41:23
 * @LastEditors: c
 * @Description: 
 * @FilePath: \music-web-backend\src\core\music\song\dto\search-song.dto.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// Copyright 2024 Administrator
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Transform } from "class-transformer";
import { IsArray, IsNumber, IsOptional, IsString } from "class-validator";
import { PageDto } from "src/common/dto/page.dto";
import { LangEnum } from "src/common/enums";
import { AudioRateEnum } from "src/common/enums/audio.enum";
import { Artist } from "../../artist/entities/artist.entity";
import { Category } from "../../category/entities/category.entity";
import { RateFileInfo } from "../../rate_file_info/entity/audio.enity";
import { Track } from "../../track/entities/track.entity";
import { VideoForm } from "../../video/dto/create-video.dto";
import { MusicUploadFile } from "./create-song.dto";

type Genre = Pick<Category, "id" | 'categoryName'>;

export class SongDto {


    //专辑的标题
    albumTitle: string;

    //此歌曲专辑的唯一code（P10003119338）
    albumAssetCode: string;

    albumIds: number[]

    //登录用户是否喜欢
    isFavorite: boolean = false;
    // //是否是VIP歌曲
    // isVip: number;
    //当前登录用户是否购买过
    isPaid: boolean = false;

    //歌曲所有的音质列表 eg:['64','128']
    allRate: string[]
    rateFileInfos: RateFileInfo[]
    //vip歌曲（试听30秒）
    trailAudioInfo?: TrailAudioInfo;

    //歌曲资源的类型（标准|高质|等）
    rateFileInfo: { [key: string]: RateFileInfo };

    introduce: string;

    id: number;

    //歌曲唯一code（"T10052891371"）
    assetId: string;

    //封面图
    pic: string | MusicUploadFile[];

    //歌曲标题
    title: string;


    //是否是VIP歌曲
    isVip: boolean;

    //语言（中文）
    lang: LangEnum;


    //发行时间
    releaseDate: Date;

    //排序
    sort: number;

    //最小音量
    meanVolume: number;

    //最大音量
    maxVolume: number;

    //歌词链接(https://img01.dmhmusic.com/0208/M00/FD/50/ChR47F3bpFyAX5VYABs_kRz7EgM751.jpg)
    lyric: string;

    //歌曲唯一code（"T10052891371"）
    TSID: string;

    //上架时间
    pushTime: Date;

    //下架时间

    downTime: string;
    createTime: string;

    //2:免费 3:收费
    payModel: number;

    //歌手列表
    artistList: Artist[];
    //歌手id列表
    artistIds?: number[];

    //类别下面的子类别(摇滚-朋克)
    genre: Category[] | number;



    //被加入的歌单列表
    trackList?: Track[];

    //歌曲MV

    video?: VideoForm;



    // genre: Genre[]

    /**
     * 以下字段未知用途
     */

    //sdk_cpm
    bizList: string[];

    //23
    cpId: number;



    //17090745
    _trackId: number;

    //'CN-Z79-19-00189'
    isrc: string;

    //0
    afReplayGain: number;
}

export class SongPageQuery extends PageDto {
    @IsOptional()
    @IsString()
    keywords?: string

    @IsOptional()
    @IsString()
    songName: string

    @IsOptional()
    @IsArray()
    @Transform(arr => arr.map(a => +a))
    @IsNumber({ allowNaN: false }, { message: "歌手id必须是数字", each: true })
    artistIds?: number[]
}

export class SongInfoDto extends SongDto {
    //"b3c1d830c35c0220f3365ebc7186c066"
    filemd5: string
    //mp3
    format: string
    //过期时间
    expireTime: number
    //16
    bits: number
}


// //文件格式
// interface RateFileInfo {
//     //资源的size大小
//     size: number;
//     //资源的格式
//     format: string;
// }

//试听30s
interface TrailAudioInfo {
    //时长
    duration: number;
    //播放的开始时间
    startTime: number;
    //音乐链接
    path: string;
    //音质
    rate: AudioRateEnum;
    //过期时间
    expireTime: number;
}

export class TrackLinkQueryDto {
    @Transform(v => +v)
    @IsNumber()
    id: number
}
export class TrackLinkVO implements TrailAudioInfo {
    duration: number;
    startTime: number;
    rate: AudioRateEnum;
    expireTime: number;

    id: number;
    path: string;
    title: string
}